<?php
class dealString{
	var $str;//待处理字符串
	public function __construct(){

	}

	public function setString($s){//设定待处理字符串
		$this->str=$s;
	}
	public function keywordToArray(){//处理函数，处理为数组,处理对象为关键词
		$result=array();
		$result=explode("\n",$this->str);
		return $result;
	}
	public function encode_json($str) {  
    	return urldecode(json_encode($this->url_encode($str)));      
	}  
	public function url_encode($str) {  
	    if(is_array($str)) {  
	        foreach($str as $key=>$value) {  
	            $str[urlencode($key)] = $this->url_encode($value);  
	        }  
	    } else {  
	        $str = urlencode($str);  
	    }  
	      
	    return $str;  
	}  
	public function urlToArray(){//处理函数，处理为数组,处理对象为关键词
		$result=array();
		$resultTemp=explode("\n",$this->str);
		foreach ($resultTemp as $key => $value) {
			if(strstr($value,"http://")||strstr($value,"https://")){
				$result[]=$value;
			}
		}
		return $result;
	}
	public function keywordToJSON(){
		return $this->encode_json($this->keywordToArray());
	}
	public function urlToJSON(){
		return $this->encode_json($this->urlToArray());
	}
} 
?>